package cloud.study.template.generate;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

/**
 * @author : forget.liu@aliyun.com
 * @date : 2020/5/17 15:37
 * @description : TODO
 */
public class GenerateMain {

    public static void main(String[] args) {
        GlobalConfig globalConfig = new GlobalConfig()
                .setDateType(DateType.ONLY_DATE)
                .setOpen(false)
                .setBaseResultMap(true)
                .setBaseColumnList(true)
                .setAuthor("angel.bin@aliyun.com")
                .setOutputDir("src\\main\\java")
                .setFileOverride(true)
                .setSwagger2(true)
                .setIdType(IdType.ASSIGN_ID)
                .setMapperName("%sMapper")
                .setXmlName("%sMapper")
                .setServiceName("I%sService")
                .setServiceImplName("%sServiceImpl")
                .setControllerName("%sController");


        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig
                .setCapitalMode(true)
                .setEntityLombokModel(true)
                .setSkipView(true)
                .setNaming(NamingStrategy.underline_to_camel)
                .setColumnNaming(NamingStrategy.underline_to_camel)
                .setEntityLombokModel(true)
                .setControllerMappingHyphenStyle(true)
                .setEntityBooleanColumnRemoveIsPrefix(true)
                .setRestControllerStyle(true)
                .setEntityTableFieldAnnotationEnable(true)
                .setLogicDeleteFieldName("is_deleted");


        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
                .setUrl("jdbc:mysql://101.37.64.142:3306/db-imr-email-v2?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8&useSSL=false")
                .setDriverName("com.mysql.cj.jdbc.Driver")
                .setUsername("root")
                .setPassword("4IF737WgQ5iz");

        PackageConfig packageConfig = new PackageConfig();
        packageConfig
                .setParent("com.imr.email")
                .setEntity("model.domain");

        TemplateConfig templateConfig = new TemplateConfig();
        templateConfig.setEntity("templates/entity.java")
                .setController("templates/controller.java")
                .setMapper("templates/mapper.java")
                .setService("templates/service.java")
                .setServiceImpl("templates/serviceImpl.java")
                .setXml("templates/mapper.xml");

        AutoGenerator generator = new AutoGenerator();
        generator.setTemplateEngine(new FreemarkerTemplateEngine())
                .setTemplate(templateConfig)
                .setStrategy(strategyConfig)
                .setDataSource(dataSourceConfig)
                .setGlobalConfig(globalConfig)
                .setPackageInfo(packageConfig)
                .execute();

    }


}
